<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>字典项编辑</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/libs/layui2.2.5/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/common.css">
    <link rel="icon" href="href="${pageContext.request.contextPath}/static/libs/uiframe/frame/static/image/code.png">
    <style type="text/css">
        .layui-input-block {
            margin-left: 130px;
            min-height: 36px;
        }
        .layui-form-label {
            float: left;
            display: block;
            padding: 9px 15px;
            width: 100px;
            font-weight: 400;
            text-align: right;
        }
    </style>
    <form class="layui-form c3form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">键值：</label>
            <div class="layui-input-block">
                <input type="text" name="value" value="${dict.value}"
                       lay-verify="v" autocomplete="off" placeholder="请输入键值名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标签：</label>
            <div class="layui-input-block">
                <input type="text" name="label" value="${dict.label}"
                       lay-verify="" autocomplete="off" placeholder="请输入标签名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型：</label>
            <div class="layui-input-block">
                <input type="text" name="type" value="${dict.type}"
                       lay-verify="" autocomplete="off" placeholder="请输入类型值" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序：</label>
            <div class="layui-input-block">
                <input type="text" name="sort" value="${dict.sort}"
                       lay-verify="" autocomplete="off" placeholder="请输入排序值" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">描述：</label>
            <div class="layui-input-block">
                <textarea name="description" value="${dict.description}"
                          placeholder="请输入描述内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="dictadd">提 交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重 置</button>
            </div>
        </div>
    </form>

    <script type="text/javascript" src="${pageContext.request.contextPath}/static/libs/layui2.2.5/layui.js"></script>
    <script>
        var dictId = '${dict.dictId}';

        layui.use(['form','layer'],function(){
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;
            <%--$("input[name='username']").val('${user.username}');--%>

            //自定义验证规则
            form.verify({
                number:function (value) {
//                    if(/^\d+\d+\d$/.test(value)){
//                        return '输入项必须为数字';
//                    }
                },

                mapName: function(value){
                    if(value.length < 2){
                        return '应用名称至少得2个字符';
                    }
                },
                description: function(value){
//                    if(value.length < 2){
//                        return '描述至少得2个字符啊';
//                    }
                }
            });

            //监听提交
            form.on('submit(mapadd)', function(data){
                var formData = data.field,url,viewData={};
                if(mapId == ""){
                    url = '${pageContext.request.contextPath}/ol/mapcreate';
                }else{
                    url = '${pageContext.request.contextPath}/ol/mapupdate';
                }
                if(formData['zoom'] != null && formData['zoom'] != ""){
                    viewData['zoom'] = formData['zoom'];
                }
                if(formData['maxZoom'] != null && formData['maxZoom'] != ""){
                    viewData['maxZoom'] = formData['maxZoom'];
                }
                if(formData['minZoom'] != null && formData['minZoom'] != ""){
                    viewData['minZoom'] = formData['minZoom'];
                }
                if(formData['center'] != null && formData['center'] != ""){
                    viewData['center'] = formData['center'];
                }
                if(formData['projection'] != null && formData['projection'] != ""){
                    viewData['projection'] = formData['projection'];
                }
                $.ajax({
                    type:'post',
                    dataType:'json',
                    url:url,
                    data:{
                        mapId:mapId,
                        mapName:formData['mapName'],
                        pixelRatio:for mData['pixelRatio'] == null || formData['pixelRatio'] == "" ? null:parseFloat(formData['pixelRatio']),
                        logo:formData['logo'],
                        view:viewData,
                        description:formData['description']
                    },
                    success:function (data) {
                        layer.msg(data.status);
                        window.parent.layIndex = null;
                        window.parent.closeAllLayer();
                    },
                    error:function (error) {
                        console.log(error);
                    }
                });
                return false;
            });
        })
    </script>
</head>
<body>

</body>
</html>
